package com.sunlake.spring.main.common.model.pay.mq.producer;

import com.sunlake.spring.main.config.RabbitMQConfig;
import com.sunlake.spring.main.common.utils.RabbitMQUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 支付消息生产者
 * 负责发送支付相关的消息
 */
@Component
@Slf4j
public class PayMessageProducer {

    @Autowired
    private RabbitMQUtils rabbitMQUtils;

    /**
     * 发送订单创建消息
     */
    public void sendOrderCreateMessage(Map<String, Object> orderInfo) {
        rabbitMQUtils.sendMessage(
            RabbitMQConfig.BUSINESS_EXCHANGE,
            RabbitMQConfig.PAY_ROUTING_KEY,
            orderInfo
        );
        log.info("订单创建消息已发送：{}", orderInfo.get("outTradeNo"));
    }

    /**
     * 发送支付结果通知
     */
    public void sendPayResultMessage(Map<String, Object> payResult) {
        rabbitMQUtils.sendMessage(
            RabbitMQConfig.BUSINESS_EXCHANGE,
            RabbitMQConfig.PAY_ROUTING_KEY,
            payResult
        );
        log.info("支付结果消息已发送：{}", payResult.get("outTradeNo"));
    }
}